/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dca.sistemascontrole.malhadecontrole;

import dca.sistemascontrole.domain.VariaveisDeControle;

/**
 *
 * @author Rafael
 */
public class ControladorPI extends MalhaFechada {

    private double kp;
    private double ki;
    private double up;
    private double ui;
    private double integralPI;

    public ControladorPI(double setpoint, double kpe, double kie) {
        super(setpoint);
        integralPI = 0;
        this.kp = kpe;
        this.ki = kie;
    }

    @Override
    protected VariaveisDeControle getNextValue(long t, double nivelTanqueSuperior, double nivelTanqueInfeior) {
        double erro;
        double U;
        erro = variaveisDeControle.getSetPoint() - nivelTanqueSuperior;
        integralPI = integralPI + ki * erro * 0.1;
        
        up = kp * erro;
        ui = integralPI;
        
        U = up + ui;
        
        variaveisDeControle.setU(U);
        variaveisDeControle.setUp(up);
        variaveisDeControle.setUi(up);
        variaveisDeControle.setErro(erro);
        
        return variaveisDeControle;
    }
}
